home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: Re: gettimeofday() makes
- Date: 1 Mar 1996 06:00:14 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4h63pe$osr@gail.ripco.com>
- NNTP-Posting-Host: golden.ripco.com
-
- Carl@dudd.uniserve.com (Carl) in <208_9602292012@dudd.uniserve.com>
- wrote:
-
- >What about if you use a function similar to the Borland clock_t() which
- >returns the amount of clock ticks since program start. Don't clock ticks
- >happen like 18 times per second on most systems?
-
- Just to forestall any misperceptions arising from the above,
-
- 1) clock_t is an aritmetic type capable of representing times. It is
- not a function. It is defined by the ISO/ANSI standard and
- Borland's use complies with the standard.
-
- 2) The function which Carl has in mind is clock:
- clock_t clock(void);
- It should determine the the implementation's best approximation for
- processor time used since the beginning of an implementation-defined
- era related to the program invocation. It is defined by the ISO/ANSI
- standard and Borland's use complies with the standard. My copy of
- Borland's documentation makes no reference to `clock ticks since
- program start' or to the value of the macro CLOCKS_PER_SEC, which is
- as it should be.
-
- 3) The frequency of the clock tick is unrelated to the use of clock().
- It returns a number of `clock_t' units, which are converted to
- seconds by dividing that number by CLOCKS_PER_SEC.* On my system, for
- example, CLOCKS_PER_SEC is 543 times as large as the freqency of the
- system clock.
-
- 4) Because the era used for the value returned is only `related' to
- program invocation, you will want (if the time from program start is
- important), to save a returned value from clock() obtained at
- program startup: `startup_clock = clock();'. If you want the time
- in clock_t units since program startup, clock()-startup_clock is a
- good approximation.
-
- * In some older implementations from Borland (and others),
- CLOCKS_PER_SEC may not be defined. They use the older macro CLK_TCK.
- The easiest thing to do here, if the header is a text file, is to edit
- the header file. Find the macro definition
- #define CLK_TCK /* whatever */
- Copy it, substituting `CLOCKS_PER_SEC' for `CLK_TCK'. Now you will no
- longer need worry about the ANSI macro name's being missing.
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-